package com.jic.interaction.weChatCardAndOffers.controller;

import com.jic.interaction.weChatCardAndOffers.common.utils.RestResult;
import com.jic.interaction.weChatCardAndOffers.model.vo.request.WxCardRequest;
import com.jic.interaction.weChatCardAndOffers.service.WeChatCardAndOffersService;
import com.jic.market.request.CouponDetailRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Auther YGH
 * @DATE 2020/11/11/13:54
 * 第一步获取access_token
 * 第二步上传logo图片
 * 第三步创建卡券
 */
@Api(value = "优惠券管理", tags = "优惠券管理", description = "AccountCheckingController")
@RequestMapping("weChatCard")
@RestController
public class WeChatCardAndOffersController {


    @Resource
    private WeChatCardAndOffersService weChatCardAndOffersService;

    @PostMapping("/getToken")
    @ApiOperation(value = "获取AccessToken", notes = "获取AccessToken")
    public RestResult<?> getAccesstToken() {
        return RestResult.success(weChatCardAndOffersService.getWeiXinApiToken());
    }

    @PostMapping("/queryCard")
    @ApiOperation(value = "查询优惠券列表", notes = "查询优惠券列表")
    public RestResult<?> queryCard(@RequestBody CouponDetailRequest couponDetailRequest) {
        weChatCardAndOffersService.queryCard();
        return RestResult.success( "");
    }
    /**
     * @Auther: YGH
     * @DATE: 2020/11/12
     * @Return:
     * @Param:
     */
    @PostMapping("/addCard")
    @ApiOperation(value = "新增优惠券", notes = "新增优惠券。")
    public RestResult<?> addCard(@RequestBody WxCardRequest wxCardRequest) {
        weChatCardAndOffersService.addCard(wxCardRequest);
        return RestResult.success("");
    }

    @PostMapping("/upLoadLogo")
    @ApiOperation(value = "卡券的商户logo: 建议像素为300*300", notes = "卡券的商户logo: 建议像素为300*300")
    public RestResult<?> upLoadLogo(@RequestBody Map map) {
        if (map.isEmpty()) return RestResult.error("123456");
        String s = weChatCardAndOffersService.upLoadLogo(map.get("filePath").toString());
        return RestResult.success("");
    }

}
